﻿function buildInfoGrid(){
    // Set up variables
    var $el, $parentWrap, $otherWrap, 
        $allTitles = $("dt").css({
            padding: 5, // setting the padding here prevents a weird situation, where it would start animating at 0 padding instead of 5
            "cursor": "pointer" // make it seem clickable
        }),
        $allCells = $("dd").css({
            position: "relative",
            top: -1,
            left: 0,
            display: "none" // info cells are just kicked off the page with CSS (for accessibility)
        });
    
    // clicking image of inactive column just opens column, doesn't go to link   
    $("#page-wrap").delegate("a","click", function(e) { 
        
        if ( !$(this).parent().hasClass("curCol") ) {         
            e.preventDefault(); 
            $(this).next().find('dt:first').click(); 
        } 
        
    });
    
    // clicking on titles does stuff
    $("#page-wrap").delegate("dt", "click", function() {
        
        // cache this, as always, is good form
        $el = $(this);
        
        // if this is already the active cell, don't do anything
        if (!$el.hasClass("current")) {
        
            $parentWrap = $el.parent().parent();
            $otherWraps = $(".info-col").not($parentWrap);
            
            // remove current cell from selection of all cells
            $allTitles = $("dt").not(this);
            
            // close all info cells
            $allCells.slideUp();
            
            // return all titles (except current one) to normal size
            $allTitles.animate({
                fontSize: "14px",
                paddingTop: 5,
                paddingRight: 5,
                paddingBottom: 5,
                paddingLeft: 5
            });
            
            // animate current title to larger size            
            $el.animate({
                "font-size": "20px",
                paddingTop: 10,
                paddingRight: 5,
                paddingBottom: 0,
                paddingLeft: 10
            }).next().slideDown();
            
            // make the current column the large size
            $parentWrap.animate({
                width: 320
            }).addClass("curCol");
            
            // make other columns the small size
            $otherWraps.animate({
                width: 140
            }).removeClass("curCol");
            
            // make sure the correct column is current
            $allTitles.removeClass("current");
            $el.addClass("current");  
        
        }
        
    });
    
   // $("#starter").trigger("click");
};  
//});
var dagtpl=['<div class="info-col"> ',
 '   <a class="" href="#"> ',
 '    <section class="panel panel-default"> ',
 '     <header class="panel-heading font-bold">  ${title}  </header> ',
 '     <div class="bg-light dk wrapper"> ',
 '     <span class="h4"><small style="position: absolute;margin-top: 20px;">未受控</small><font color="red">${unctrlNum}</font></span> ',
 '      <span class="pull-right h4"><small style="position: absolute;margin-top: 20px;">问题数</small><font color="red">${errorlNum}</font></span> ',
 '      <div class="text-center m-b-n m-t-sm"> ',
 '       <div class="sparkline" data-type="line" data-height="65" data-width="310px" data-line-width="2" data-line-color="#dddddd" data-spot-color="#bbbbbb" data-fill-color="" data-highlight-line-color="#fff" data-spot-radius="3" data-resize="true">',
 '         280,320,220,385,450,320,345,250,250,250,400,380 ',
 '       </div> ',
 '      </div> ',
 '     </div> ',
 '     <div class="panel-body"> ',
 '      <div class="row"> ',
 '       <div class="col-xs-4"> ',
 '        <small class="text-muted block">总实体数</small> <span>${sumNum}</span> ',
 '       </div> ',
 '       <div class="col-xs-4"> ',
 '        <small class="text-muted block">总规则数</small> <span>${sumRuleNum}</span> ',
 '       </div> ',
 '       <div class="col-xs-4"> ',
 '        <small class="text-muted block">受控数</small> <span>${ctlNum}</span> ',
 '       </div> ',
 '      </div> ',
 '     </div> ',
 '    </section> </a> ',
 '   <dl> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">表</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>${tabctlNum}</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>${taberrorlNum}</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：${tabRuleNum}</p><p>未受空的数：${tabunctlNum}</p><p>已受控数据：${tabctlNum}</p>存在问题数：${taberrorlNum}</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">指标</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">接口</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">OpenApi</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">程序</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">应用</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   <dt class="row">',
 '      <div class="col-xs-4">分发</div>',
 '      <div class="col-xs-4"> <small class="text-muted" >受控数</small> <span>33</span></div>',
 '      <div class="col-xs-4"> <small class="text-muted ">问题数</small> <span>33</span></div>',
 '   </dt>',
 '    <dd><p>设置规则数：40</p><p>未受空的数：304</p><p>已受控数据：679</p>存在问题数：890</dd> ',
 '   </dl> ',
 '  </div>',
 '	'].join("");

function getZB(zbcodes){
	  var retData;
	  $.ajax({
	    async: false,
	    url: '/' + contextUrl + "/catalog/zb/select?zbcodes=" + zbcodes, 
	    type: "GET",
	    dataType: "json",
	    success: function(data){
	                retData = data;
	             }
	  });
	  return retData;
	}
var store = getZB(["dagdqsumNum","dagdqctlNum","dagdqsumRuleNum","dagdqtabctlNum","dagdqtabRuleNum","dagdqtaberrorlNum","dagdqtabsumNum"]);
var agestore = getZB(["storagetabctlNum","storagetabsumNum"]);
var stdstore = getZB(["stdctlNum","stdsumRuleNum","stdtabctlNum","stdtaberrorlNum","stdtabRuleNum"]);
var buildDagHtml=function(config){
	$("#page-wrap").empty();
	config=[
	     {title:'总体情况',errorlNum:234,unctrlNum:203,sumNum:1023,ctlNum:234,sumNum:203,sumRuleNum:12342},
	     {title:'数据架构',errorlNum:234,unctrlNum:203,sumNum:1023,ctlNum:234,sumNum:203,sumRuleNum:12342},
	     {title:'元数据管理',errorlNum:234,unctrlNum:203,sumNum:1023,ctlNum:234,sumNum:203,sumRuleNum:12342},
	     {title:'标准化管理',errorlNum:234,unctrlNum:203,ctlNum:stdstore.stdctlNum.value,sumNum:store.dagdqsumNum.value,sumRuleNum:stdstore.stdsumRuleNum.value,tabctlNum:stdstore.stdtabctlNum.value,taberrorlNum:stdstore.stdtaberrorlNum.value,tabRuleNum:stdstore.stdtabRuleNum.value,tabunctlNum:store.dagdqtabsumNum.value-stdstore.stdtabctlNum.value},
	     {title:'数据质量',errorlNum:234,unctrlNum:203,ctlNum:store.dagdqctlNum.value,sumNum:store.dagdqsumNum.value,sumRuleNum:store.dagdqsumRuleNum.value,tabctlNum:store.dagdqtabctlNum.value,taberrorlNum:store.dagdqtaberrorlNum.value,tabRuleNum:store.dagdqtabRuleNum.value,tabunctlNum:store.dagdqtabsumNum.value-store.dagdqtabctlNum.value},
	     {title:'生命周期',errorlNum:234,unctrlNum:203,ctlNum:agestore.storagetabctlNum.value,sumNum:store.dagdqsumNum.value,sumRuleNum:1,tabRuleNum:1,tabctlNum:agestore.storagetabctlNum.value,tabunctlNum:agestore.storagetabsumNum.value-agestore.storagetabctlNum.value},
	     {title:'安全管理',errorlNum:234,unctrlNum:203,sumNum:1023,ctlNum:234,sumNum:203,sumRuleNum:12342},
	     {title:'过程管理',errorlNum:234,unctrlNum:203,sumNum:1023,ctlNum:234,sumNum:203,sumRuleNum:12342}
	     
	 ];
	 
	$.template('template', dagtpl); 
 	$.tmpl('template', config).appendTo('#page-wrap');
	 
}
var sparkGraph=function(selecter){
 
	 $(".sparkline").each(function(){
		var $data = $(this).data();
		 
		($data.type == 'pie') && $data.sliceColors && ($data.sliceColors = eval($data.sliceColors));
		($data.type == 'bar') && $data.stackedBarColor && ($data.stackedBarColor = eval($data.stackedBarColor));
		$data.valueSpots = {'0:': $data.spotColor};
		$(this).sparkline('html', $data);
	});
 
}